#    Copyright 2014 Gregory Roby
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.


#************************BEGIN Add Include Files to Path************************
import sys, os
ConfigurationDirectory = '/opt/coopconfig'
NeededPaths=[ConfigurationDirectory]
for path in NeededPaths:
    if(not path in sys.path):
        sys.path.append(path)
import coopgisconfig
os.system('export DJANGO_SETTINGS_MODULE=djangoproject.settings')



#************************END   Add Include Files to Path************************
import os
DEBUG=True
COOPGISServerIndicator=os.path.exists('/opt/coopgisnotupdated/ThisIsTheServer.txt')
#COOPGISServerIndicator=True


#The exact line above needs to start (without quotes and replace the '-' with '=' while on the server:
#COOPGISServerIndicator-True
#On Test Server 1:30 PM 06/15/2010
COOPGISPath='/opt/coopgis/'
COOPGISUpdatePath='/opt/coopgisupdate/'
COOPGISUpdatePathFTPRootReadOnly='/opt/coopgisupdate/ftprootreadonly/'
COOPGISUpdatePathFTP='/opt/coopgisupdate/ftprootreadonly/ftp/'
COOPGISUpdatePathInProgress='/opt/coopgisupdate/inprogress/'
COOPGISUpdatePathCompleted='/opt/coopgisupdate/completed/'
COOPGISUpdatePathCancelled='/opt/coopgisupdate/cancelled/'
COOPGISUpdatePathRepository='/var/www/downloadrepository/'
COOPGISUpdatePathRepositoryDownload=COOPGISUpdatePathRepository + 'coopgis/'
COOPGISUpdateLogFileName=COOPGISUpdatePath + 'update.log'
COOPGISAssemblyEditorLogFileName=COOPGISUpdatePath + 'assemblyeditor.log'


COOPGISUsersWithDelayAfterUpdating=['SCRUBBED']
COOPGISUpdateWWWPath='/var/www/coopgisupdate/'
COOPGISServerIPAddress='192.168.100.74'  #192.168.100.75 is the Test Machine, 192.168.100.74 is Production
COOPGISVersion=['COOPGIS', '06/6/2014', '0', '8', '1', 'DEVELOPMENT']  #Program Name, Date, Release, Major, Minor, Status
COOPGISInVirtualMachineIndicator=os.path.exists('/opt/InVirtualMachine')  #Create this folder on the Virtual Machine Image
COOPGISCommandTemporaryUploadFileName=COOPGISPath + 'command/commandupload.txt'
COOPGISCommandTemporaryUploadResultsFileName=COOPGISPath + 'command/commanduploadresult.txt'
COOPGISCommandTemporaryServerVerifiedResultsFileName=COOPGISPath + 'command/serververifiedallcommands.txt'
COOPGISTemporaryFileName=COOPGISPath + 'TemporaryFile'
COOPGISCommandUpdateTemporaryStatusFile=COOPGISPath + 'command/updatestatus.txt'
COOPGISHCIToolScanResultFile=COOPGISPath + 'command/hcitoolscanresult.txt'
COOPGISBlueToothMacAddressTargetFileName=COOPGISPath + 'scripts/ConnectToBluetooth'
COOPGISBlueToothMacAddressFileName='/opt/coopgisnotupdated/bluetoothmacaddress.txt'
COOPGISMapFilePath=COOPGISPath + 'mapserver/dynamic/'
COOPGISMapFileDBLines="CONNECTIONTYPE postgis\nCONNECTION 'host=localhost user=coopgisdbuser password=coopgis dbname=coopgis'\n"
COOPGISGPSFileName="/opt/coopgis/fromgps/Locations.csv"
COOPGISSRID=4326
COOPGISGPSSRID=4326
COOPGISStakerWorkOrderReportPath='/var/www/coopgisstakerworkorders/'
COOPGISCISVendorCompatibleUnitFileName='/opt/coopgis/DataNotPartOfCOOPGIS/CISStaker.txt'
COOPGISBackupLocation='/opt/coopgisbackup/'
COOPGISFTPUpdateUserName='SCRUBBED'
COOPGISFTPUpdatePassword='SCRUBBED'
COOPGISDistanceMultiplier=1 #Multiplier used for all distance calculations, intended to be Conversion Factor to Convert Feet to Whatever unit used by the SRID


COOPGISTempImagePath='/opt/coopgis/media/tempimage/'
COOPGISStartupMusicSourceFileName='/opt/coopgis/media/music/coopgisstartup.mp3'
COOPGISStartupMusicDestinationFileName='/var/www/music/coopgisstartup.mp3'
COOPGISStartupMusicDestinationPathName='/var/www/music/'

#The following are Application Names:
COOPGISStakerApplicationName='Staker'
COOPGISMapSetupApplicationName='MapSetup'
COOPGISInventoryCollectionApplicationName='InventoryCollection'
COOPGISViewerApplicationName='Viewer'
COOPGISJointUseEditorApplicationName='JointUseEditor'
COOPGISAssemblyEditorApplicationName='AssemblyEditor'
COOPGISCircuitAnalysisApplicationName='CircuitAnalysis'
COOPGISPoleTreatmentApplicationName='PoleTreatment'
COOPGISVegetationManagerApplicationName='VegetationManager'
COOPGISCostEstimateApplicationName='CostEstimate'
COOPGISManagementConsoleApplicationName='ManagementConsole'
COOPGISBoardDistrictApplicationName='BoardDistrict'
COOPGISLandmarkEditorApplicationName='LandmarkEditor'
COOPGISStakerMiniMapApplicationName='StakerMiniMap'
COOPGISRoadEditorApplicationName='RoadEditor'
COOPGISConditionEditorApplicationName='ConditionEditor'
COOPGISConditionReportApplicationName='ConditionReport'
COOPGISConditionDispatchApplicationName='ConditionDispatch'
COOPGISConditionAssignmentUserApplicationName='ConditionAssignmentUser'
COOPGISConditionCreateApplicationName='ConditionCreate'
COOPGISConditionWorkApplicationName='ConditionWork'
COOPGISConditionReviewApplicationName='ConditionReview'
COOPGISGPSTraceApplicationName='GPSTrace'
COOPGISSubstationApplicationName='Substation'
COOPGISGeneralApplicationName='General'
COOPGISWarehouseApplicationName='Warehouse'
COOPGISCISApplicationName='CIS'
COOPGISCISRestrictedApplicationName='CISRESTRICTED'
COOPGISGroundRodTestApplicationName='GroundRodTest'
COOPGISOutdoorLightingApplicationName='OutdoorLighting'


COOPGISAllApplications=[]
COOPGISAllApplications.append(COOPGISStakerApplicationName)
COOPGISAllApplications.append(COOPGISMapSetupApplicationName)
COOPGISAllApplications.append(COOPGISInventoryCollectionApplicationName)
COOPGISAllApplications.append(COOPGISViewerApplicationName)
COOPGISAllApplications.append(COOPGISJointUseEditorApplicationName)
COOPGISAllApplications.append(COOPGISAssemblyEditorApplicationName)
COOPGISAllApplications.append(COOPGISCircuitAnalysisApplicationName)
COOPGISAllApplications.append(COOPGISPoleTreatmentApplicationName)
COOPGISAllApplications.append(COOPGISVegetationManagerApplicationName)
COOPGISAllApplications.append(COOPGISManagementConsoleApplicationName)
COOPGISAllApplications.append(COOPGISBoardDistrictApplicationName)
COOPGISAllApplications.append(COOPGISLandmarkEditorApplicationName)
COOPGISAllApplications.append(COOPGISStakerMiniMapApplicationName)
COOPGISAllApplications.append(COOPGISRoadEditorApplicationName)
COOPGISAllApplications.append(COOPGISConditionEditorApplicationName)
COOPGISAllApplications.append(COOPGISConditionReportApplicationName)
COOPGISAllApplications.append(COOPGISConditionAssignmentUserApplicationName)
COOPGISAllApplications.append(COOPGISConditionDispatchApplicationName)
COOPGISAllApplications.append(COOPGISConditionCreateApplicationName)
COOPGISAllApplications.append(COOPGISConditionWorkApplicationName)
COOPGISAllApplications.append(COOPGISConditionReviewApplicationName)
COOPGISAllApplications.append(COOPGISGPSTraceApplicationName)
COOPGISAllApplications.append(COOPGISSubstationApplicationName)
COOPGISAllApplications.append(COOPGISWarehouseApplicationName)
COOPGISAllApplications.append(COOPGISCISApplicationName)
COOPGISAllApplications.append(COOPGISCISRestrictedApplicationName)
COOPGISAllApplications.append(COOPGISGroundRodTestApplicationName)

#Add A Division Table that holds a list of circuits, FIXME to make this more portable, more details are in Issue Tracker
COOPGIS_StMatthewsCircuits=[200, 201, 202, 203, 204, 205, 206, 401, 402, 403, 404, 405, 406, 601, 602, 603, 604, 605, 606, 800, 801, 802, 803, 804, 805, 806]
COOPGIS_SanteeCircuits=[500, 501, 502, 503, 504, 505, 506, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1201, 1202, 1203, 1204, 1205, 1300, 1301, 1302, 1303, 1304]
COOPGIS_RichlandCircuits=[300, 301, 302, 303, 304, 305, 700, 701, 702, 703, 704, 705, 900, 901, 902, 903, 904, 905]



TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)
MANAGERS = ADMINS

DATABASES={}
DATABASES['default']={
#'ENGINE': 'django.db.backends.postgis',           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'coopgis',             # Or path to database file if using sqlite3.
'USER': 'coopgisdbuser',             # Not used with sqlite3.
'PASSWORD': 'coopgis',         # Not used with sqlite3.
'HOST': 'localhost',             # Set to empty string for localhost. Not used with sqlite3.
'PORT': '',             # Set to empty string for default. Not used with sqlite3.
}



#************************BEGIN Optional OMS Import************************
try:
    IncludePath="/opt/oms"
    if(not IncludePath in sys.path):
        sys.path.append(IncludePath)
    import COOPGISOMSSetup
    COOPGISOMSSetup.DefineDatabases(DATABASES)
except:
    pass
#************************BEGIN Add OMS Files to Path************************
#************************BEGIN Optional AMR Import************************
try:
    IncludePath="/opt/amr"
    if(not IncludePath in sys.path):
        sys.path.append(IncludePath)
    import COOPGISAMRSetup
    COOPGISAMRSetup.DefineDatabases(DATABASES)
except:
    pass
#************************BEGIN Add AMR Files to Path************************
#************************BEGIN Optional CIS Import************************
try:
    IncludePath="/opt/cis"
    if(not IncludePath in sys.path):
        sys.path.append(IncludePath)
    import COOPGISCISSetup
    COOPGISCISSetup.DefineDatabases(DATABASES)
except:
    pass
#************************BEGIN Add AMR Files to Path************************





class COOPGISDatabaseRouter(object):
    def db_for_read(self, model, **hints):
        try:
            using=model.using
        except:
            using='default'
        return using
    def db_for_write(self, model, **hints):
        try:
            using=model.using
        except:
            using='default'
        return using
    def allow_relation(self, obj1, obj2, **hints):
        try:
            using=model.using
        except:
            using='default'
        return using
    def allow_syncdb(self, db, model):
        try:
            using=model.using
        except:
            using='default'
        if(using == 'default' and db == 'default'):
            return True
        else:
            return False

DATABASE_ROUTERS=['djangoproject.settings.COOPGISDatabaseRouter']



# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'MST'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/opt/coopgis/media/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'COOPGISDEV328905tyu3984gh34809tyh213%@!#%(*@#%*@$THgj3ui54gherukigh39854th248oghwslkhndfbm,jtgyyhyhyhyghedsfrgo8hy34glm.,xmzcv,.bmcv.x,bm'



# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
#Deprecated in Django 1.4:
#    'django.template.loaders.filesystem.load_template_source',
#    'django.template.loaders.app_directories.load_template_source',
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware', #v1.4
    'django.middleware.doc.XViewMiddleware',
)

ROOT_URLCONF = 'djangoproject.urls'

TEMPLATE_DIRS = (
    '/opt/coopgis/djangoproject/templates',
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.sites',
    'django.contrib.auth',

    'django.contrib.contenttypes',
    'django.contrib.sessions',

    'django.contrib.admin',
    'django.contrib.gis',
    'django.contrib.messages',
    'djangoproject'
)

#section added due to deprecation in v1.4
TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.core.context_processors.tz',
    'django.contrib.messages.context_processors.messages'
)


